local zcdiy_zhiheng = fk.CreateSkill {
    name = "zcdiy_zhiheng",
    tags = { Skill.Switch },
}

Fk:loadTranslationTable {
    ["zcdiy_zhiheng"] = "制衡",
    [":zcdiy_zhiheng"] = "转换技，出牌阶段，阳：你可以摸X张牌，弃置X张牌；阴：你可以弃置X张牌，摸X张牌(X为此技能本回合的发动次数+1)。",

    ["$zcdiy_zhiheng1"] = "三思而行，游刃有余",
    ["$zcdiy_zhiheng2"] = "制衡联合，稳而不乱",

}
zcdiy_zhiheng:addEffect("active", {
    anim_type = "switch",
    prompt = function(self, player)
        local n = 1 + player:usedSkillTimes(zcdiy_zhiheng.name, Player.HistoryPhase)
        if player:getSwitchSkillState("zcdiy_zhiheng", true) == fk.SwitchYang then
            return "制衡：你可以摸" .. n .. "张牌，然后弃置" .. n .. "张牌"
        else
            return "制衡：你可以弃" .. n .. "张牌，然后摸" .. n .. "张牌"
        end
    end,
    can_use = function(self, player)
        if player:getSwitchSkillState("zcdiy_zhiheng") == fk.SwitchYang then
            return player:usedSkillTimes(zcdiy_zhiheng.name, Player.HistoryPhase) < 999
        else
            return player:getHandcardNum() >= 1 + player:usedSkillTimes(zcdiy_zhiheng.name, Player.HistoryPhase)
        end
    end,
    card_filter = Util.FalseFunc,
    target_filter = Util.FalseFunc,
    on_use = function(self, room, effect)
        local player = effect.from
        local n = player:usedSkillTimes(zcdiy_zhiheng.name, Player.HistoryPhase)
        if player:getSwitchSkillState("zcdiy_zhiheng") == fk.SwitchYang then
            player:drawCards(n, zcdiy_zhiheng.name)
            if not player.dead then
                room:askToDiscard(player,
                    {
                        min_num = n,
                        max_num = n,
                        include_equip = true,
                        skill_name = zcdiy_zhiheng.name,
                        prompt = "制衡：你需要弃置" .. n .. "张牌",
                        cancelable = false
                    })
            end
        else
            room:askToDiscard(player,
                {
                    min_num = n,
                    max_num = n,
                    include_equip = true,
                    skill_name = zcdiy_zhiheng.name,
                    prompt = "制衡：你需要弃置" .. n .. "张牌",
                    cancelable = false
                })
            if not player.dead then
                player:drawCards(n, zcdiy_zhiheng.name)
            end
        end
    end,
})

return zcdiy_zhiheng
